#ifndef MESSAGETEXTEDIT_H
#define MESSAGETEXTEDIT_H

#include <QDragEnterEvent>
#include <QMimeData>
#include <QTextEdit>
#include <QVector>
#include <QWidget>
#include "global.h"

class MessageTextEdit : public QTextEdit
{
    Q_OBJECT
public:
    explicit MessageTextEdit(QWidget *parent = nullptr);
    ~MessageTextEdit();
    QVector<MsgInfo> getMsgList();
    void insertFileFromUrl(const QStringList &urls);
signals:
    void send();

    // QWidget interface
protected:
    virtual void keyPressEvent(QKeyEvent *event) override;
    virtual void dragEnterEvent(QDragEnterEvent *event) override;
    virtual void dropEvent(QDropEvent *event) override;

private:
    void insertImage(const QString &url);
    void insertTextFile(const QString &url);

    // QTC_TEMP
    // QTextEdit interface
protected:
    virtual bool canInsertFromMimeData(const QMimeData *source) const override;
    virtual void insertFromMimeData(const QMimeData *source) override;

private:
    bool isImage(QString url);
    void insertMsgList(QVector<MsgInfo> &list, QString flag, QString text, QPixmap pix);
    QStringList getUrl(QString text);
    QPixmap getFileIconPixmap(const QString &url);
    QString getFileSize(qint64 size);
private slots:
    void textEditChanged();

private:
    QVector<MsgInfo> _msgList;
    QVector<MsgInfo> _getMsgList;
};

#endif // MESSAGETEXTEDIT_H
